<?php


namespace app\common\cachemodel\live;


use app\common\model\BaseCache;
use XznsTools\cache\CacheManage;

class LiveAwardResultUser extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.live_award_result_user';

    protected $cacheModel = 'live.award_result';

    /**
     * 获取抽奖活动中奖用户信息
     */
    public function getAwardActiveResult(int $awardActiveId)
    {
        $resData = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $awardActiveId)
            ->getDataAndSet(function () use ($awardActiveId)
            {
                try
                {
                    $data = $this->alias('a')->join('wechat_backup_07_18_14_43_00.app_user u', 'u.id=a.uid')->where('a.award_acitve_id', $awardActiveId)->column('u.uen,u.nickname', 'a.uid');

                    return json_encode($data);
                }
                catch (\Exception $e)
                {
                    return '';
                }
            });

        if ($resData)
        {
            return json_decode($resData, true);
        } else
        {
            return [];
        }
    }
}
